package com.fenghongzhang.kuaishou.mvp.register.presenter;



import android.util.Log;

import com.fenghongzhang.kuaishou.common.Constant;
import com.fenghongzhang.kuaishou.mvp.login.entity.UserInfoBean;
import com.fenghongzhang.kuaishou.mvp.register.contract.RegisterContract;
import com.fenghongzhang.mvp_lib.presenter.BasePresenter;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class RegisterPresenter extends BasePresenter<RegisterContract.IRegisterModel, RegisterContract.IRegisterView> {

    private static final String TAG = "LoginPresenter";

    public RegisterPresenter(RegisterContract.IRegisterModel mModel, RegisterContract.IRegisterView mView) {
        super(mModel, mView);
    }

    public void register(){
        mModel.register(mView.getName(), mView.getPwd(), new Observer<UserInfoBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(UserInfoBean registerInfoBean) {
                int code = registerInfoBean.getCode();

                if(code == Constant.SUCCESS){
                    Log.i(TAG, "onNext: 注册成功!");
                    mView.isRegisterOk(registerInfoBean);
                }else{
                    Log.i(TAG, "onNext: 注册失败!");
                    mView.showMsg(registerInfoBean.getMsg());
                }
            }

            @Override
            public void onError(Throwable e) {
                Log.i(TAG, "onError: "+e.getMessage());
            }

            @Override
            public void onComplete() {

            }
        });
    }
}
